/* eslint-disable max-len */
/* eslint-disable no-multiple-empty-lines */
/* eslint-disable prettier/prettier */
import { connect } from "react-redux";
import React, { PureComponent } from "react";
import { View, StyleSheet, ScrollView, Text, TouchableOpacity, Alert, Image } from "react-native";
import { Divider, Utils, TYFlatList, Popup, TopBar } from "tuya-panel-kit";
import TYSdk from "../../api";
import dpCodes from "../../config/dpCodes";
import LowWaterView from "./lowWater";
import CleanCottonView from "./cleanCotton";
import CleanPumpView from "./cleanPump";
import DetectorProblemView from "./detectorProblem";
import PumpNoConnectView from "./pumpNoConnect";
import PumpNoWaterView from "./pumpNoWater";
import PumpNoWorkView from "./pumpNoWork";
import PumpProblemView from "./pumpProblem";

import FeedTooMuchView from "./feedTooMuch";
import GrassLightTooLongView from "./grassLightTooLong";
import WaterTempWarnView from "./waterTempWarn";
import FilterTimeOutView from "./filterTimeOut";
import style from '../../config/style';
import strings from "../../i18n/strings";
import Res from '../../res';

const { convertX: cx } = Utils.RatioUtils;
const { convertY: cy, viewWidth, viewHeight } = Utils.RatioUtils;

const TYEvent = TYSdk.event;
const TYDevice = TYSdk.device;
const TYNative = TYSdk.native;
const TYMobile = TYSdk.mobile;

const {
  trigger_status: trigger_statusCode
} = dpCodes;

class ErrorListScene extends PureComponent {

  constructor(props) {
    super(props);
    //console.log(props);
    this.state = {
      showTop: true,
    };
  }

  topView() {
    return (
      <TopBar.Container
        background="#FFFFFF"
        style={{ height: TopBar.height }}
        contentStyle={{ height: TopBar.height, marginTop: 10 }}
      >
        <TopBar.Action size={20} source={Res.fback} color="#4C4C4C" onPress={() => TYSdk.Navigator.pop()} />
        <TopBar.Content  />
      </TopBar.Container>
    );
  }

  /* errorValue 传参跳转对应View [1, 2, 4, 8, 16, 32, 64, 128, 256, 512]; */
  render() {
    const { showTop } = this.state;
    const { errorValue } = this.props;

    return (
      <View style={style.container}>
        { showTop ? this.topView() : null }
        <ScrollView
          accessibilityLabel="ErrorListScene_ScrollView"
          contentContainerStyle={ errorValue === 25 || errorValue === 8 || errorValue === 512 ? style.scrollLongView : style.scrollView}
        >
          {/* 水草灯时间过长 */}
          {errorValue === 1 ? (<GrassLightTooLongView />) : null}
          {/* 水泵故障 E3 */}
          {errorValue === 2 ? (<PumpProblemView />) : null}
          {/* 水泵低水位 E1 */}
          {errorValue === 4 ? (<LowWaterView />) : null}
          {/* 水泵堵转 E2 -> 清洁水泵 */}
          {errorValue === 8 ? (<CleanPumpView type={0} />) : null}
          {/* 水泵未连接 */}
          {errorValue === 16 ? (<PumpNoConnectView />) : null}
          {/* 今日喂食份数过多 */}
          {errorValue === 32 ? (<FeedTooMuchView />) : null}
          {/* 水温提醒 */}
          {errorValue === 64 ? (<WaterTempWarnView />) : null}
          {/* 物理滤材过期 */}
          {errorValue === 128 ? (<FilterTimeOutView type={0} />) : null}
          {/* 生化滤材过期 */}
          {errorValue === 256 ? (<FilterTimeOutView type={1} />) : null}
          {/* 水泵过滤棉清洗提醒 */}
          {errorValue === 512 ? (<CleanCottonView />) : null}

          {/* 水泵不出水、异响、空转 */}
          {errorValue === 22 ? (<PumpNoWaterView />) : null}
          {/* 水泵不工作 */}
          {errorValue === 23 ? (<PumpNoWorkView />) : null}
          {/* 温度探头故障 E4 */}
          {errorValue === 24 ? (<DetectorProblemView />) : null}
          {/* 清洁水泵 */}
          {errorValue === 25 ? (<CleanPumpView type={1} />) : null}

        </ScrollView>
      </View>
    );
  }

}

const styles = StyleSheet.create({
  // container: {
  //   flex: 1,
  //   backgroundColor: "#fff",
  // },

});

export default connect(({ dpState }) => ({
  trigger_status: dpState[trigger_statusCode]
}))(ErrorListScene);
